#include "gtest/gtest.h"
#include "sgEigenSpace.h"
#include <complex.h>
#include <random> 
#include <chrono>

using namespace SG::Algebra;  // Open the namespace
//using SG::DataStructure::Common::TOLERANCE;

class EigenSpaceTest : public ::testing::Test
{
public:
    static void SetUpTestSuite ()
    {
    }
};




TEST_F (EigenSpaceTest, correctness)
{
   
    const int rows = 5;
    const int cols = 5;
    const int nnz = 10;
    const int repeat_nnz = 3;
    
    typedef Eigen::Triplet<double> T;
    std::vector<T> triplets;
    triplets.reserve(nnz);
    triplets.emplace_back(0, 0, 1.0);
    triplets.emplace_back(1, 1, 2.0);
    triplets.emplace_back(2, 2, 3.0);
    triplets.emplace_back(3, 3, 4.0);
    triplets.emplace_back(4, 4, 5.0);
    triplets.emplace_back(0, 4, 0.5); 
    triplets.emplace_back(4, 4, 5.0);  
    triplets.emplace_back(4, 4, 5.0);  
    triplets.emplace_back(4, 4, 5.0); 
    triplets.emplace_back(4, 0, 0.5);  

   

    // 2. call convertTripletsToMKLSparse
    Eigen::SparseMatrix<double> mat(rows, cols);

    convertTripletsToMKLSparse(triplets.begin(), triplets.end(), mat);

    Eigen::SparseMatrix<double,Eigen::ColMajor> mat2(rows, cols);
    mat2.setFromTriplets(triplets.begin(), triplets.end());

    ASSERT_EQ(mat.rows(), mat2.rows());
    ASSERT_EQ(mat.cols(), mat2.cols());
    ASSERT_EQ(mat.nonZeros(), mat2.nonZeros());  
    EXPECT_DOUBLE_EQ(mat.coeff(0, 0), mat2.coeff(0, 0));
    EXPECT_DOUBLE_EQ(mat.coeff(4, 4), mat2.coeff(4, 4));
    EXPECT_DOUBLE_EQ(mat.coeff(4, 0), mat2.coeff(4, 0));
    EXPECT_DOUBLE_EQ(mat.coeff(0, 4), mat2.coeff(0, 4));
    EXPECT_DOUBLE_EQ(mat.coeff(4, 0), 0.5);

}

